require(['topBar', 'highcharts'], function () {
	var postData = {};
	$('#top').topBar({
        left: [{
            type: 'filter-more',
            search: function () {
                search();
            },
            item: [
                {
                    text: '时间快捷',
                    name1: 'beginTime',
                    name2: 'endTime',
                    type: 'dateLine'
                }
            ]
        }
        ]
    });
	commonFun.leftTreeNodeClickObj['getCarId'] = function(event,
			treeId, treeNode) {
		nodeType = treeNode.type;
		postData.carId = treeNode.id;
		postData.carType = treeNode.typeDetail;
		
	};
	
	function search(){
		if (postData && postData.carId && postData.carId != '' && postData.carType != 'CAT00001' && postData.carType != 'CAT00002') {//判断是否新能源
			postData.beginTime = $("#top").parent().getValues().beginTime;
			postData.endTime = $("#top").parent().getValues().endTime;
			$("#noneVoltage, #noneTemperature").hide();
			$("#voltageChart, #tempratureChart").show();
			$.ajaxExt({
				"url": "/batteryExtreme/getBatteryVoltageData.htm",
				"data": postData
			}).done(function(data){
				if(data && data.length){
					var categories = [], data1 = [], data2 = [], data3 = [];
					for(var i=0;i<data.length;i++){
						categories.push(data[i].rcrdTime);
						data1.push(data[i].differVtg);
						data2.push(data[i].highestBteryVtg);
						data3.push(data[i].lowestBteryVtg);
					}
					createChart($("#voltageChart"), "电压极差分析", categories, data1, data2, data3, 'v', '电压差', '最高电压', '最低电压', '电压差', '电压');
				}
			});
			
			$.ajaxExt({
				"url": "/batteryExtreme/getBatteryTemperatureData.htm",
				"data": postData
			}).done(function(data){
				if(data && data.length){
					var categories = [], data1 = [], data2 = [], data3 = [];
					for(var i=0;i<data.length;i++){
						categories.push(data[i].rcrdTime);
						data1.push(data[i].differTept);
						data2.push(data[i].highestTept);
						data3.push(data[i].lowestTept);
					}
					createChart($("#tempratureChart"), "温度极差分析", categories, data1, data2, data3, '℃', '温度差', '最高温度', '最低温度', '温度差', '温度');
				}
			});
			
		}else{
			$.messager.alert("提示", "请先选择车辆！", "info");
		}
	}
	
	function createChart(obj, title, categories, data1, data2, data3, unit, txt1, txt2, txt3, yAxis1, yAxis2){
		obj.highcharts({
	        chart: {
	            zoomType: 'xy'
	        },
	        credits:{  
                enabled:false  
            },
	        title: {
	            text: title
	        },
	        xAxis: [{
	            categories: categories,
	            minTickInterval: 100,
	            crosshair: true
	        }],
	        yAxis: [{
	            labels: {
	                format: '{value}'+unit,
	                style: {
	                    color: Highcharts.getOptions().colors[1]
	                }
	            },
	            title: {
	                text: yAxis1,
	                style: {
	                    color: Highcharts.getOptions().colors[1]
	                }
	            }
	        }, {
	            title: {
	                text: yAxis2,
	                style: {
	                    color: Highcharts.getOptions().colors[0]
	                }
	            },
	            labels: {
	                format: '{value}'+unit,
	                style: {
	                    color: Highcharts.getOptions().colors[0]
	                }
	            },
	            opposite: true
	        }],
	        tooltip: {
	        	crosshairs: true,
	            shared: true
	        },
	        series: [{
	            name: txt1,
	            type: 'spline',
	            data: data1,
	            tooltip: {
	                valueSuffix: unit
	            }
	        },{
	            name: txt2,
	            type: 'spline',
	            yAxis: 1,
	            data: data2,
	            tooltip: {
	                valueSuffix: unit
	            }
	        },{
	            name: txt3,
	            type: 'spline',
	            yAxis: 1,
	            data: data3,
	            tooltip: {
	                valueSuffix: unit
	            }
	        }]
	    });
	}
	
});